﻿/**
 * @author sminutoli
 * Version 1.1
 * El from del message es un extId, será cuestión de la capa de presentación vincular eso con un contacto
 * 
 */
 
import com.dinmax.flash.central.extension.message.TextMessage;
import com.dinmax.flash.central.extension.user.UserFactory;
import com.dinmax.flash.utilities.xml.XMLUtils;
//import com.dinmax.flash.utilities.xml.XMLParameters;
import com.dinmax.flash.utilities.date.JavaDateParser;

class com.dinmax.flash.central.extension.message.TextMessageFactory {
	
	public static function getTextMessages(node:XMLNode):Array {
		
		var msgs:Array = new Array();
		for(var msg:XMLNode = node.firstChild; msg != null; msg=msg.nextSibling){
			if(msg.nodeType == 1){
				msgs.push(TextMessageFactory.getTextMessage(msg));
			};
		};
		return msgs;
	}
	
	public static function getTextMessage(node:XMLNode):TextMessage {
		//trace("TextMessageFactory.as | getTextMessage() \n---\nnode:\n"+node+"\n" );
		var timeDate:Number = Number(XMLUtils.getAttribute(node, "date"));
		var messageDate:Date = JavaDateParser.convertDate(timeDate);
		var msg:TextMessage = new TextMessage();
		msg.setId(XMLUtils.getAttribute(node, "id"));
		msg.setTime(messageDate);
		msg.setSubject(unescape(XMLUtils.getAttribute(node, "subject")));
		msg.setBody(unescape(XMLUtils.getAttribute(node, "body")));
		msg.setState(XMLUtils.getAttribute(node, "state"));
		msg.setFrom(Number(XMLUtils.getAttribute(node, "from")));
		//msg.setFrom(UserFactory.getUser(XMLUtils.getNode(node, "user")));
		
		return msg;
	};
	
};